﻿
namespace System
{
    using System.Diagnostics.Contracts;

    public static class TypeExtensions
    {

        /// <summary>
        /// 1.  SimpleTypeName`1[Namespace.OtherTypeName] --> "SimpleTypeName"
        /// 2.  SimpleTypeName --> "SimpleTypeName"
        /// </summary>
        public static string GetSimpleName(this Type type)
        {
            Contract.Requires(type != null);

            bool isGenericType = type.IsGenericType;

            string simpleName = isGenericType
                ? type.Name.Substring(0, type.Name.IndexOf('`'))
                : type.Name;

            return simpleName;
        }

    }
}
